﻿using System;
using System.Web.Mvc;

namespace Wwtfly.BBS.ForeControllers.Attributes
{
    /// <summary>
    /// Controller 或 Action 所在文件夹, 例: Module/Tag
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class HasFolderAttribute : ActionFilterAttribute {
        /// <summary>
        /// 构造函数
        /// </summary>
        public HasFolderAttribute() : this(string.Empty) { }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="folder">文件夹相对路径</param>
        public HasFolderAttribute(string folder) {
            this.Folder = folder;
        }
        /// <summary>
        /// 文件夹相对路径
        /// </summary>
        public string Folder { get; set; }
        /// <summary>
        /// 重写 OnActionExecuting
        /// </summary>
        /// <param name="filterContext">上下文</param>
        public override void OnActionExecuting(ActionExecutingContext filterContext) {
            base.OnActionExecuting(filterContext);
            filterContext.RouteData.DataTokens.Add("__View__Folder", this.Folder.Trim('\\').Trim('/'));
        }
    }
}